package com.gitee.cirnochat.common.utils;


import com.gitee.cirnochat.common.exception.BusinessException;
import com.gitee.cirnochat.common.model.enums.ErrorCode;
import com.gitee.cirnochat.login.model.entity.IprangeInfo;

public final class IpInfoUtil {
    private IpInfoUtil() {
        // Prevent instantiation
        throw new UnsupportedOperationException("Utility class");
    }

    public static String getIpDescription(IprangeInfo ip) {
        if (ip == null) {
            return "未知地区";
        }
        return String.format("%s %s %s",
                ip.getCountry(),
                ip.getProvince(),
                ip.getCity());
    }

    public static String getIpLocation(IprangeInfo ip) {
        if (ip == null) {
            throw new BusinessException(ErrorCode.SYSTEM_ERROR,"IP信息不能为空");
        }
        if (ip.getLocation() != null)
            return ip.getLocation();
        if (ip.getCity() != null)
            return ip.getCity();
        if (ip.getProvince() != null)
            return ip.getProvince();
        if (ip.getCountry() != null)
            return ip.getCountry();
        return "未知地区";
    }
}
